package com.eugene.enums;

import java.util.ArrayList;
import java.util.List;

import com.eugene.element.FnCalendar;
import com.eugene.element.IntRate;

public enum EForwardMeth {
	CONSTANT,
	FORWARDING {
		public List<IntRate> getForwardTermStructure(FnCalendar baseDate, FnCalendar fwdDate, List<IntRate> curveRates, EInterpolation interpolMeth){
/*			List<IntRate> fwdRates = new ArrayList<IntRate>();
			IntRate fwdRate;
			double rate;
			IntRate baseRate = new IntRate(baseDate, baseDate, fwdDate,
											interpolMeth .getInterpolation(curveRates, fwdDate));
			
			for(IntRate aa:curveRates){
				fwdRate = new IntRate(baseDate,baseDate, fwdDate.addTerm(aa.getMaturity(),true), 
						              interpolMeth.getInterpolation(curveRates, fwdDate.addTerm(aa.getMaturity(), true)));
				
				rate = getForwardRate(baseDate,fwdDate,baseRate,fwdRate);
				
				fwdRate.setIntRateId(aa.getIntRateId());
				fwdRate.setFwdDate(fwdDate);
				fwdRate.setMaturity(aa.getMaturity());
				fwdRate.setCompound(aa.getCompound());
				fwdRate.setDayCount(aa.getDayCount());
				fwdRate.setIntRateValue(rate);
				fwdRates.add(fwdRate);
			}

			return fwdRates;*/
			return curveRates;

		}
	
		public double getForwardRate(FnCalendar baseDate, FnCalendar fwdDate, IntRate baseRate, IntRate rate){
			double intFactor1;
			double intFactor2;
			double tf1;
			double tf2;
			
			tf1 = baseRate.getDayCount().getTimeFactor(baseDate, fwdDate);
			intFactor1 = baseRate.getCompound().getIntFactor(baseRate.getIntRateValue(),tf1);
			tf2 = rate.getDayCount().getTimeFactor(baseDate, rate.getIntDate());
			intFactor2 = rate.getCompound().getIntFactor(rate.getIntRateValue(),tf2);
			
			return rate.getCompound()
							.getIntRateFrom(intFactor2/intFactor1, 
											rate.getDayCount().getTimeFactor(fwdDate, rate.getIntDate()));
		}
	}
	;
	
	public double getForwardRate(FnCalendar baseDate, FnCalendar fwdDate, IntRate baseRate,IntRate rate){
		return rate.getIntRateValue();
	}
	
	public List<IntRate> getForwardTermStructure(FnCalendar baseDate, FnCalendar fwdDate, List<IntRate> curveRates, EInterpolation interpolMeth){
		return curveRates;
	}


}
